package coder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.TooLongFrameException;

import java.util.Arrays;
import java.util.List;

public class MyDoCoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        System.out.println("当前可读数据长度:"+byteBuf.readableBytes());
        if(byteBuf.readableBytes()>=4){

            if(byteBuf.readableBytes()>1024){
                channelHandlerContext.close();
            }else{
                byte[] bytes = new byte[4];
                byteBuf.readBytes(bytes);
                System.out.println(Arrays.toString(bytes));
                list.add(NumberConvertByte.ByteArrayToInt(bytes));
            }

        }
    }
}
